<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * listtriggers.php
 * Began: November 2007
 * 
 * 
 ******************************/
 
define('EQDKP_INC', true);
define('IN_ADMIN', true);
$eqdkp_root_path = './../';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('a_item_');

$sort_order = array(
    0 => array('trigger_date desc', 'trigger_date'),
    1 => array('trigger_holder', 'trigger_holder desc'),
    2 => array('trigger_name', 'trigger_name desc'),
    3 => array('raid_name', 'raid_name desc')
);

$current_order = switch_order($sort_order);

$total_triggers = $db->query_first('SELECT count(*) FROM ' . TRIGGERS_TABLE);
$start = ( isset($_GET['start']) ) ? $_GET['start'] : 0;

$sql = 'SELECT i.trigger_id, i.trigger_name, i.trigger_holder, i.trigger_date, i.raid_gained_id, r.raid_name
        FROM ' . TRIGGERS_TABLE . ' i, ' . RAIDS_TABLE . ' r
        WHERE r.raid_id=i.raid_gained_id
        ORDER BY '.$current_order['sql']. '
        LIMIT '.$start.','.$user->data['user_ilimit'];

$listitems_footcount = sprintf($user->lang['listpurchased_footcount'], $total_triggers, $user->data['user_ilimit']);
$pagination = generate_pagination('listtriggers.php'.$SID.'&amp;o='.$current_order['uri']['current'], $total_triggers, $user->data['user_ilimit'], $start);

if ( !($triggers_result = $db->query($sql)) )
{
    message_die('Could not obtain item information', 'Database error', __FILE__, __LINE__, $sql);
}

while ( $trigger = $db->fetch_record($triggers_result) )
{
    $tpl->assign_block_vars('triggers_row', array(
        'ROW_CLASS' => $eqdkp->switch_row_class(),
        'DATE' => ( !empty($trigger['trigger_date']) ) ? date($user->style['date_notime_short'], $trigger['trigger_date']) : '&nbsp;',
        'HOLDER' => ( !empty($trigger['trigger_holder']) ) ? $trigger['trigger_holder'] : '&lt;<i>Not Found</i>&gt;',
        'U_VIEW_HOLDER' => ( !empty($trigger['trigger_holder']) ) ? '../viewmember.php'.$SID.'&amp;' . URI_NAME . '='.$trigger['trigger_holder'] : '',
        'NAME' => stripslashes($trigger['trigger_name']),
        'U_VIEW_TRIGGER' => 'addtrigger.php'.$SID.'&amp;' . URI_ITEM . '='.$trigger['trigger_id'],
        'RAID' => ( !empty($trigger['raid_name']) ) ? stripslashes($trigger['raid_name']) : '&lt;<i>Not Found</i>&gt;',
        'U_VIEW_RAID' => ( !empty($trigger['raid_name']) ) ? 'addraid.php'.$SID.'&amp;' . URI_RAID . '='.$trigger['raid_id'] : '')
    );
}
$db->free_result($triggers_result);

$tpl->assign_vars(array(
    'L_DATE' => $user->lang['date'],
    'L_HOLDER' => $user->lang['holder'],
    'L_TRIGGER' => $user->lang['trigger'],
    'L_RAID' => $user->lang['raid'],
    
    'O_DATE' => $current_order['uri'][0],
    'O_HOLDER' => $current_order['uri'][1],
    'O_NAME' => $current_order['uri'][2],
    'O_RAID' => $current_order['uri'][3],
    
    'U_LIST_TRIGGERS' => 'listtriggers.php'.$SID.'&amp;',
    
    'START' => $start,
    'S_HISTORY' => true,
    'LISTITEMS_FOOTCOUNT' => $listitems_footcount,
    'ITEM_PAGINATION' => $pagination)
);

$eqdkp->set_vars(array(
    'page_title'    => sprintf($user->lang['admin_title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listtriggers_title'],
    'template_file' => 'admin/listtriggers.html',
    'display'       => true)
);
?>
